<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <button>点击</button>
    <script>
    var btn = document.getElementsByTagName('button')[0];
    // btn.addEventListener("click",function(){alert(1)},false); //普通
    // btn.attachEvent("onclick",function(){alert(1)}) //IE8 及以下
    function addEvent(dom,type,fun){
        dom.addEventListener?dom.addEventListener(type,fun,false):dom.attachEvent("on"+type,fun)
    }
    addEvent(btn,"click",function(){alert(1)})
    </script>
</body>
</html>